package com.sf.fy.uav.applet.controller.operate;


import com.sf.fy.uav.common.request.operate.ActivityAddRequest;
import com.sf.fy.uav.common.request.operate.ActivityEditRequest;
import com.sf.fy.uav.common.request.operate.SysActivityRequest;
import com.sf.fy.uav.common.request.order.DealRequest;
import com.sf.fy.uav.common.response.operational.SysActivityResponse;
import com.sf.fy.uav.common.utils.Rs;
import com.sf.fy.uav.rest.ActivityRest;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 活动表 前端控制器
 * </p>
 *
 * @author LTQ
 * @since 2023-08-16
 */
@RestController
@RequestMapping("/home/activity")
@Tag(name = "活动设置管理", description = "活动设置管理")
public class SysActivityController {

    @Autowired
    private ActivityRest activityRest;

    @PostMapping("add")
    @Operation(tags = "新增活动", description = "新增活动")
//    @Parameter(name = "activityEditRequest.activityName", description = "活动名称")
//    @Parameter(name = "activityEditRequest.startActivityTime", description = "开始活动时间")
//    @Parameter(name = "activityEditRequest.endActivityTime", description = "结束活动时间")
//    @Parameter(name = "activityEditRequest.rewardRule", description = "奖励规则，如果是邀请新用户下单则传invite_new_users")
//    @Parameter(name = "activityEditRequest.processedBy", description = "处理人")
//    @Parameter(name = "activityEditRequest.rewardAmount", description = "奖励金额")
    @ApiResponses({
            @ApiResponse(responseCode = "200", description = "成功,非200失败")
    })
    public Rs<Void> addActivity(@RequestBody @Validated ActivityAddRequest activityAddRequest) {
        activityRest.addActivity(activityAddRequest);
        return Rs.success();
    }

    @PostMapping("autoLoadAndUnload")
    @Operation(tags = "自动上下架", description = "自动上下架")
    @ApiResponses({
            @ApiResponse(responseCode = "200", description = "成功,非200失败")
    })
    public Rs<Void> autoLoadAndUnload() {
        activityRest.autoLoadAndUnload();
        return Rs.success();
    }


    @PostMapping("edit")
    @Operation(tags = "编辑活动", description = "编辑活动")
    @Schema(title = "activityEditRequest", name = "activityEditRequest", description = "活动编辑请求", type = "结构体", format = "")
//    @Parameter(name = "activityEditRequest.activityName", description = "活动名称", example = "活动名称")
//    @Parameter(name = "activityEditRequest.startActivityTime", description = "开始活动时间", example = "开始活动时间")
//    @Parameter(name = "activityEditRequest.endActivityTime", description = "结束活动时间", example = "结束活动时间")
//    @Parameter(name = "activityEditRequest.rewardRule", description = "奖励规则，如果是邀请新用户下单则传invite_new_users", example = "奖励规则")
//    @Parameter(name = "activityEditRequest.processedBy", description = "处理人", example = "处理人")
//    @Parameter(name = "activityEditRequest.rewardAmount", description = "奖励金额", example = "奖励金额")
    @ApiResponses({
            @ApiResponse(responseCode = "200", description = "成功,非200失败")
    })
    public Rs<Void> editActivity(@RequestBody @Validated ActivityEditRequest activityEditRequest) {
        activityRest.editActivity(activityEditRequest);
        return Rs.success();
    }

    @GetMapping("get-activity")
    @Operation(tags = "分页获取活动列表", description = "分页获取活动列表")
    @ApiResponse(description = "获取相关活动", content = @Content(mediaType = "application/json"))
    @CrossOrigin
    @Parameter(name = "activityName", description = "活动名称")
    @Parameter(name = "status", description = "活动状态（0, \"未开始\" 1, \"展示中\" 2, \"已结束\" 3, \"已下架/手动下架\"）")
    @Parameter(name = "page", description = "页码")
    @Parameter(name = "size", description = "单页条数")
    public Rs<List<SysActivityResponse>> getActivity(@RequestParam Integer page, @RequestParam Integer size, @RequestParam(required = false) String activityName,
                                                     @RequestParam(required = false) Integer status) {

        SysActivityRequest sysActivityRequest = new SysActivityRequest();
        sysActivityRequest.setPage(page);
        sysActivityRequest.setSize(size);
        sysActivityRequest.setStatus(status);
        sysActivityRequest.setActivityName(activityName);
        return Rs.success(activityRest.getActivity(sysActivityRequest));
    }

    @GetMapping("get-total")
    @Parameter(name = "activityName", description = "活动名称")
    @Parameter(name = "status", description = "活动状态（0, \"未开始\" 1, \"展示中\" 2, \"已结束\" 3, \"已下架/手动下架\"")
    @CrossOrigin
    @Operation(tags = "获取总条数", description = "获取总条数")
    public Rs<Long> getTotal(@RequestParam(required = false) String activityName,
                             @RequestParam(required = false) Integer status) {
        return Rs.success(activityRest.getTotal(activityName, status));
    }

    @Operation(tags = "停止活动", description = "停止活动")
//    @Parameter(name = "dealRequest.id", description = "id", example = "id")
//    @Parameter(name = "dealRequest.processedBy", description = "处理人", example = "处理人")
    @PostMapping("off")
    public Rs<Void> off(@RequestBody DealRequest dealRequest) {
        activityRest.off(dealRequest);
        return Rs.success();
    }

    @PostMapping("delete")
    @Operation(tags = "软删除活动", description = "软删除活动")
//    @Parameter(name = "dealRequest.id", description = "id", example = "id")
//    @Parameter(name = "dealRequest.processedBy", description = "处理人", example = "处理人")
    @ApiResponses({
            @ApiResponse(responseCode = "200", description = "成功,非200失败")
    })
    public Rs<Void> delete(@RequestBody DealRequest dealRequest) {
        activityRest.delete(dealRequest);
        return Rs.success();
    }
}
